<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>NovaCube - Panel</title>
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	<!-- Latest compiled and minified CSS -->
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
	<!-- Optional theme -->
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
	<!-- Font awesome pour les icones -->
  <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
  <script src="../lioche/ckeditor/ckeditor.js"></script>
</head>

<?php
include("bdd.php");
?>

<body style="background-image: url('fond.png');background-repeat: no-repeat;background-attachment: fixed;background-position: center;">

<nav class="navbar navbar-default">
  <div class="container-fluid">
    <div class="navbar-header">
      <a class="navbar-brand" href="">NovaCube - Rédaction</a>
    </div>

    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li><a href="index.php"><i class="fa fa-home"></i> Accueil</a></li>
        <li><a href="http://novacube.fr/forums"><i class="fa fa-comments"></i> Forum</a></li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li class="active"><a href="logout.php"><b>Déconnexion</b></a></li>
      </ul>
    </div>
  </div>
</nav>

<?php

session_start();

if(isset($_SESSION['pseudo'])){
?>

<div class="container-fluid">

  <div class="row">
    <div class="col-md-1">
    </div>

    <div class="col-md-10">
      <div class="panel panel-default">
          <div class="panel-heading"><div class="panel-heading"><i class="fa fa-heart"></i> Bienvenue sur ton panel de rédaction, <?php echo($_SESSION['pseudo']) ?> !</div></div>
          <div class="panel-body">
            
            <form method="post">
            <center>
            <label for="titre">Titre de l'article:</label><br />
            <div class="input-group">
              <span class="input-group-addon" id="sizing-addon2"><i class="fa fa-spinner fa-pulse"></i></span>
              <input type="text" name="titre" class="form-control" placeholder="Titre" aria-describedby="sizing-addon2">
            </div>
            <br />
            <label for="article">Contenu de l'article:</label><br />
            <textarea name="article" cols="120" rows="15"></textarea>
            <br /><hr>
            <input class="btn btn-default" type="submit" name="submit" value="Poster">
            </center>
            </form>  



          </div>
        </div>
    </div>

    <div class="col-md-1">
    </div>
  </div>

<?php }else{ header('Location:login.php');} ?>

</body>

<?php
if(isset($_POST['submit'])){
  $pseudo = $_SESSION['pseudo'];
  $corps = htmlspecialchars_decode(trim($_POST['article']));
  $titre = htmlspecialchars_decode(trim($_POST['titre']));

  if(empty($titre) || empty($corps)){
    ?>
      <center>
        <div class="col-md-3"></div>
        <div class="col-md-6">
          <div class="alert alert-danger" role="alert">
            <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
            <span class="sr-only">Error:</span>
            <b>Veuillez compléter tout les champs !</b>
          </div>
        </div>
        </center>
  <?php
  }else{
    mysqli_query($connexion, "INSERT INTO articles VALUES('', '$pseudo', '$corps', '$titre', NOW())");
    header('Location:index.php');
  }

}

?>